﻿using System;
using System.Data;
using System.Collections.Generic;
using ZHDJ.MobileInterface.Common;

namespace ZHDJ.MobileInterface
{
    public partial class GetLawKnowledgeList : AbstractBasePage
    {
        protected override OutParam BusinessProcess<InParam, OutParam>(InParam inParam)
        {
            // 业务逻辑返回的响应对象  
            GetLawKnowledgeOutParam result = new GetLawKnowledgeOutParam();
            GetLawKnowledgeInParam param = new GetLawKnowledgeInParam();
            string logMsg = "";
            bool isFlag = true;

            try
            {
                param = inParam as GetLawKnowledgeInParam;


                if (param.page_no * param.page_count <= 0)
                {
                    result.code = "0";
                    result.desc = "当前页,以及页记录条数必须为大于0的正整数";

                    isFlag = false;
                }

                if (isFlag)
                {
                    DataSet ds = SXT.Party.Law.BLL.CommonUtils.GetLawKnowledgeList(param.CaseType, param.Keywords, param.page_no, param.page_count, "MobileService");
                    if (ds != null && ds.Tables.Count == 2)
                    {
                        LawKnowledgeData itemTemp;
                        result.data.total_pages = CommonUtils.GetTotalPages(Convert.ToInt32(ds.Tables[1].Rows[0][0]), param.page_count);
                        foreach (DataRow dr in ds.Tables[0].Rows)
                        {
                            itemTemp = new LawKnowledgeData();
                            itemTemp.KnowledgeID = dr["KnowledgeID"].ToString();
                            itemTemp.Title = dr["Title"].ToString();
                            itemTemp.Content = dr["Content"].ToString().Replace("src=\"/fs/UploadFiles/party", "src=\"http://www.ith71.cn/fs/UploadFiles/party");

                            result.data.list.Add(itemTemp);
                        }

                    }
                }

                logMsg = result.desc;
            }
            catch (Exception ex)
            {
                result.code = "0";
                result.desc = "操作异常，多次出现请联系管理员";
                logMsg = ex.Message + ":" + ex.StackTrace;
            }

            CommonUtils.InsertMobileInterfaceLog(SystemCode + "-GetLawKnowledge", SerializeHelper.JsonSerializer<GetLawKnowledgeInParam>(param), logMsg);
            return result as OutParam;
        }

        protected void Page_Load(object sender, System.EventArgs e)
        {
            if (string.Compare(Request.QueryString["Safe"], "False", true) == 0)
                ProcessRequest<GetLawKnowledgeInParam, GetLawKnowledgeOutParam>();
            else
                SafeProcessRequest<GetLawKnowledgeInParam, GetLawKnowledgeOutParam>();
        }
    }

    #region 请求参数
    public class GetLawKnowledgeInParam
    {
        /// <summary>
        /// 必填 当前页
        /// </summary>
        public int page_no
        { get; set; }

        /// <summary>
        /// 必填，每页记录条数
        /// </summary>
        public int page_count
        { get; set; }

        /// <summary>
        /// 类型  0：劳资纠纷  1：刑事纠纷
        /// </summary>
        public string CaseType
        { get; set; }

        /// <summary>
        /// 查询条件
        /// </summary>
        public string Keywords
        { get; set; }
    }
    #endregion


    #region 结果参数
    public class GetLawKnowledgeOutParam
    {
        public GetLawKnowledgeOutParam()
        {
            code = "1";
            desc = "操作成功";
            data = new LawKnowledgeList();
        }

        public string code
        { get; set; }

        public string desc
        { get; set; }

        public LawKnowledgeList data
        { get; set; }

    }

    public class LawKnowledgeList
    {
        public LawKnowledgeList()
        {
            total_pages = 0;
            list = new List<LawKnowledgeData>();
        }

        public List<LawKnowledgeData> list { get; set; }
        /// <summary>
        /// 总页数
        /// </summary>
        public int total_pages
        { get; set; }
    }

    public class LawKnowledgeData
    {
        /// <summary>
        /// 法律知识ID
        /// </summary>
        public string KnowledgeID
        { get; set; }

        /// <summary>
        /// 标题
        /// </summary>
        public string Title
        { get; set; }

        /// <summary>
        /// 内容
        /// </summary>
        public string Content
        { get; set; }
    }
    #endregion
}